package com.example.com.skills_utf8;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.utils.g;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 处理聊天底部
 * Created by matengfei on 15/7/20.
 */
public class _62_1imjoFragment extends Fragment {

    GridView gridview ;
    Adapter adapter = new Adapter();
    List<Integer> listdata = new ArrayList<Integer>();




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_62_1_imjo, null);

        gridview = (GridView)view.findViewById(R.id.gridview);


        initImjo();


        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Integer obj = (Integer)parent.getItemAtPosition(position);
                _62_1Activity activity = (_62_1Activity)getActivity();
                activity.update(obj);

            }
        });
        gridview.setAdapter(adapter);

        return view;
    }


    void initImjo(){


        listdata.clear();
        for (Map.Entry<String, Object> entry : g.imjo.entrySet()) {
            int value = (int)entry.getValue();
            listdata.add(value);

        }



    }


    class Adapter extends BaseAdapter{

        @Override
        public int getCount() {
            return listdata.size();
        }

        @Override
        public Object getItem(int position) {
            return listdata.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            Integer resource = listdata.get(position);

            if(convertView == null){
                //LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                convertView = new ImageView(getActivity());

            }

            ImageView iv = (ImageView)convertView;
            iv.setImageResource(resource);




            return convertView;
        }
    }



}
